package cn.gson.springboot.model.service;


import cn.gson.springboot.model.dao.CustomerServiceDao;
import cn.gson.springboot.model.mapper.CustomerServiceMapper;
import cn.gson.springboot.model.pojos.Customerservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class CustomerserviceService {
    @Autowired
    CustomerServiceDao customerServiceDao;
    @Autowired
    CustomerServiceMapper customerServiceMapper;

    //新增
    public void addCustomerservice(Customerservice customerservice){
        customerServiceDao.save(customerservice);//一次保存一个对象
    }

    //删除
    public void deleteOne(int serviceId){
        customerServiceDao.deleteById(serviceId);
    }

    //查找所有
    public List<Customerservice> selectAll(String search,Integer type){
        return (List<Customerservice>)customerServiceMapper.selectAll( search, type);
    }

   /* //通过id查找
    public Customerservice selectOne(int serviceId){
        return customerServiceMapper.selectOne(serviceId);
    }*/

    //根据id修改
    public void alter(int serviceId,Customerservice customerservice){
         if ( customerServiceDao.findById(serviceId)!=null){//找到该对象
             Customerservice customerservice1=customerServiceDao.findById(serviceId).get();
             customerservice1.setServiceTheme(customerservice.getServiceTheme());
             customerServiceDao.save(customerservice1);
         }
    }
}
